using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using Newtonsoft.Json;

namespace Karma.Framework.Core.Metadata.Mapping
{
    [ActiveRecord("[EntityField]")]
    public class EntityField : Field
    {

        [JoinedKey]
        public override Int64 Id { get; set; }

        [Property(NotNull = true)]
        public string Tpl { get; set; }

        public virtual LinkQuery Query
        {
            get { return (_Query == null || _Query.Count == 0 ? null : _Query[0]); }
            set
            {
                if (_Query == null)
                {
                    _Query = new List<LinkQuery> { value };
                }
                _Query[0] = value;
            }
        }

        [JsonIgnore]
        [HasMany(ColumnKey = "[EntityField]", Cascade = ManyRelationCascadeEnum.All,
            Lazy = false, Table = "[LinkQuery]")]
        protected virtual IList<LinkQuery> _Query { get; set; }

    }
}